﻿@using System.Data
@{

    Layout = "~/Areas/Admin/Views/Shared/AdminLayout.cshtml";
    DataTable table = ViewData["sort"] as DataTable;
}
<style>
    * {
        overflow: auto;
    }
</style>
<div class="searchpanel">
    <div class="seatchtool">
        <div class="operationtool">
          
            <a id="del">删除</a>
        </div>
        <div class="operationsearch">
            <label>订单号：</label><input type="text" id="orderno" value="" style="height: 20px; float: left; " />

            <a id="search">查询</a>
        </div>
    </div>
</div>
@*订单号  金额 物流 运费 状态 收货地址  会员名称 联系电话 购买商品 时间*@ 
<table class="datatable">
    <tr>
        <th width="30">选择<input type="checkbox" id="checkall" /></th>
        <th width="200">订单号</th>
        <th width="200">购买商品</th>
        <th width="200">金额</th>
        <th width="300">物流</th>
        <th width="100">运费</th>
        <th width="200">物流编号</th>
        <th width="200">状态</th><th width="200">备注</th>
        <th width="300">收货地址</th>
        <th width="100">会员名称</th>
        <th width="200">联系电话</th>
        <th width="300">时间</th>
        <th></th>
    </tr>
    <tbody id="list"></tbody>


</table>
<div id="Pagination" class="pagination" style="">
</div>
<link href="/Scripts/paging/pagination.css" rel="stylesheet" />
<script src="/Scripts/paging/jquery.pagination.js"></script>

<script>


    $(function () {
        getlist(0);

        //选择全部
        $("#checkall").click(function () {
            if ($("#checkall").attr("checked")) {
                $("#list input[type=checkbox]").attr("checked", "true");
            } else {
                $("#list input[type=checkbox]").removeAttr("checked");
            }
        });

        //查询
        $("#search").click(function () {
            getlist(0);
        });


        //  删除
        $("#del").click(function () {
            if (confirm("确定删除数据吗？")) {
                var id = "";
                $("#list input[type=checkbox]").each(function () {
                    if ($(this).attr("checked")) {
                        id += $(this).val() + ",";
                    }
                });
                if (id == "") {
                    alert("请选择要删除的数据！");
                    return false;
                }
                id = id.substring(0, id.length - 1);
                alert(id);
                $.post("@Url.Action("DelOrder")", { orderno: id }, function (row) {
                    if (row > 0) {
                        getlist(0);
                    } else {
                        alert("删除失败！");
                    }
                });
            }

        });
    });


    var pageCount = 10;
    function getlist(pageIndex) {
        var orderno = $("#orderno").val();
    
        $.post("@Url.Action("GetOrder")", { sid: 3, pageIndex: pageIndex * pageCount, pageCount: pageCount, orderNo: orderno }, function (data) {
            var obj = JSON.parse(data);
            var count = obj.count[0].count;
            var gprice = 0;
            var str = "";
            var status = "";
            for (var i = 0; i < obj.data.length; i++) {
                var item = obj.data[i];
                if (item.Status == "1") {
                    status = "未付款";
                }else if (item.Status=="2") {
                    status = "待发货";
                }else if (item.Status=="3") {
                    status = "已发货";
                }else if (item.Status=="4") {
                    status = "已收货";
                }

                str += "<tr>" +
                    "<td><input type=\"checkbox\"  value=" + item.OrderNo + " /></td>" +
                    "<td width=\"\">" + item.OrderNo + "</td>" +
                    "<td width=\"300\">";
                for (var j = 0; j < obj.data1.length; j++) {
                    var item1 = obj.data1[j];
                    gprice += parseFloat(item1.Price);
                    if (item.Id == item1.OId) {
                        str += "<a >" + item1.GoodsName + "&nbsp;商品属性：" + item1.Attr + "&nbsp;数量：" + item1.Count + "</a><br/><br/>";
                    }
                }
                str += "</td>" +
        "<td width=\"\">" + item.TotalPrice + "</td>" +
        "<td width=\"\">" + item.ExpressName + "</td>" +
        "<td width=\"\">" + item.Freight + "</td>" +
        "<td width=\"\">" + (item.WlNo == null ? "--" : item.WlNo) + "</td>" +
        "<td width=\"\">" + status + "</td>" + "<td width=\"\">" + (item.Remark == null ? "--" : item.Remark) + "</td>" +
        "<td width=\"\">" +(item.Address==null?"--":item.Address) + "</td>" +
       "<td width=\"\">" + (item.UserName == null ? "--" : item.UserName) + "</td>" +
        "<td width=\"\">" + (item.Tell == null ? "--" : item.Tell) + "</td>" +
        "<td width=\"\">" + item.Date.replace("T", " ") + "</td><td></td>" +
    "</tr>";
                //str += "<div class=\"order_list\">" +
                //    "<div class=\"order_info\">" +
                //    "<label style=\"float: left;\">订单号：" + item.OrderNo + "</label>" +
                //    "<label style=\"float: right;\">时间：" + (item.Date.substring(0, 10)) + "</label>" +
                //    "</div>";

            }

            $("#list").html(str);

            $("#Pagination").pagination(count, {
                callback: PageCallback,
                prev_text: '上一页', //上一页按钮里text
                next_text: '下一页', //下一页按钮里text
                items_per_page: pageCount, //显示条数
                num_display_entries: 5, //连续分页主体部分分页条目数
                current_page: pageIndex, //当前页索引
                num_edge_entries: 1 //两侧首尾分页条目数
            });

        });
    }

    //分页回调函数
    function PageCallback(index) {
        getlist(index);
    }
</script>
